/*
 * 自己做的一个商品添加
 */
<?php	namespace Admin\Controller;
class ShopController extends CommonController
{
	protected $db;
	public function __init()
	{
		$this->db = new \Common\Model\Shop;
	}
	public function index()
	{
		$ShopData = $this->db->get();
//		p($ShopData);
		View::with('ShopData',$ShopData);
		View::make();
	}
	public function add()
	{
		if(IS_POST)
		{
			if(!$this->db->store())
			{
				View::error($this->db->getError());
			}else
			{
				View::success('添加成功',U('index'));
			}
		}
		$ShopCateData = new \Common\Model\Cate;
		$ShopCateData = $ShopCateData->get();
		$ShopCateData = Data::tree($ShopCateData,'cname','cid','cfid');
//		p($ShopCateData);
		$ShopBrandData = new \Common\Model\Brand;
		$ShopBrandData = $ShopBrandData->get();
//		p($ShopBrandData);
		View::with('ShopBrandData',$ShopBrandData);
		View::with('ShopCateData',$ShopCateData);
		View::make();
	}
	public function endAjax()
	{
		$typeattrData = new \Common\Model\Typeattr;
		
		if(IS_AJAX)
		{
			$val = $_POST['val'];
//			p($val);die;
			$CateValData = Db::table('cate')->where('cid',$val)->pluck('oftype_lid');
//			p($CateValData);
			$typeattrData = $typeattrData ->where('typeattr_lid',$CateValData)->get();
			foreach ($typeattrData as $k => $v) {
				$typeattrData[$k]['xvalue'] = explode(',', $v['xvalue']);
			}
//			p($typeattrData);
			echo json_encode($typeattrData);
		}
		
	}
}
